<?php

namespace addons\zzuser\controller\api;

use addons\zzcash\model\UserM;
use addons\zzuser\model\UserTokenM;
use addons\zzuser\service\EncryptS;
use app\common\controller\Backend;

class UserInfo extends Backend
{
    protected $noNeedRight = 'index';

    public function index()
    {
        $token = input('token');
        if ($token) {
            $user_token = UserTokenM::where('token', EncryptS::token($token))->find();
            if (!$user_token) {
                $this->error('error token 1');
            }
            if (isset($token['expiretime']) && $token['expiretime'] < time()) {
                $this->error('error token 2');
            }
            $user = UserM::where('id', $user_token['user_id'])->find();
            if (!$user) {
                $this->error('error token 3');
            }
            $this->success('', $user);
        }
        $this->error();
    }
}
